package com.hucii.app.activity;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Toast;

import com.hucii.app.MyApplication;
import com.hucii.app.MyConstans;
import com.hucii.app.R;
import com.hucii.app.service.UpdateCheckService;
import com.hucii.app.utils.UtilsLog;
import com.hucii.app.view.BaseLayout;

public abstract class BaseActivity extends Activity implements MyConstans {

	public BaseActivity() {
		mContext = this;
		mApp = MyApplication.getSelf();

	}

	public void checkUpdate() {

		new UpdateCheckService(this).start();
	}

	protected Context mContext;
	protected MyApplication mApp;

	protected BaseLayout baseLayout;

	/**
	 * 设置布局
	 * 
	 * @param layoutResId
	 *            布局id
	 */
	protected void setView(int layoutResId) {
		baseLayout = new BaseLayout(mContext, layoutResId);
		setContentView(baseLayout);

	}

	public BaseLayout getBaseLayout() {
		return baseLayout;
	}

	/**
	 * 自定义标题
	 * 
	 * @param left
	 *            左边
	 * @param title
	 *            中间标题
	 */
	protected void setTitle(String left, String title) {
		setTitle(title);
	}

	/**
	 * 自定义标题
	 * 
	 * @param left
	 *            左边按钮
	 * @param title
	 *            标题
	 * @param right
	 *            右边按钮
	 */
	protected void setTitle(String left, String title, String right) {
		setTitle(title);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		UtilsLog.i("msg", "base activity key down");
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			exit();
			return true;
		}
		return super.onKeyDown(keyCode, event);
	}

	private void exit() {
		finish();
		overridePendingTransition(0, R.anim.push_right_out);
	}

	/**
	 * 设置标题
	 * 
	 * @param title
	 */
	private void setTitle(String title) {
		baseLayout.setTitle(title);
	}

	/**
	 * 处理标题右边按钮
	 */
	protected void onRightBtnClick() {

	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		if (mContext == this) {
			super.onCreate(savedInstanceState);
		}
	}

	/**
	 * 检查软件版本更新信息
	 * 
	 * @return
	 */
	protected void checkForUpDate() {

		// mApp.getUpdateManager().checkForUpDate();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}
}
